import commonConstants from "@/common/commonConstants";
import commonMethod from "@/common/commonMethod";

/**
 * 推演配置类
 */
class ScenarioConfiguration{

    constructor(){
        this.configurations = [];
        this.configurationTYpes = new Map();
        this._initDefualtConfigurations()
    }

    /**
     * 初始化默认的配置
     */
    _initDefualtConfigurations(){
        this.configurations.push(
            new Configurantion("decisionMaking",commonConstants.deductionModel.rehearsal,commonConstants.dataOperateType.Scenario,"确定想定模式"),
            new Configurantion("attributePlane",false,commonConstants.dataOperateType.Marker,"是否开启属性面板"),
            new Configurantion("trackable",true,commonConstants.dataOperateType.Track,"推演中是否展示航迹"),
            new Configurantion("markerable",true,commonConstants.dataOperateType.Monitor,"是否开启标绘"),
            new Configurantion("measureable",false,commonConstants.dataOperateType.Monitor,"是否开启测绘工具"),
            new Configurantion(commonConstants.configurationKey.layerable,false,commonConstants.dataOperateType.Layer,"是否开启图层"),
            new Configurantion("noteTaker",false,commonConstants.dataOperateType.NoteTaker,"是否开启记录员"),
            new Configurantion("dataConnect",false,commonConstants.dataOperateType.DataHandler,"开启后台数据持久化"),
            new Configurantion("dataLoadurl",undefined,commonConstants.dataOperateType.DataHandler,"加载想定方法连接"),
            new Configurantion("dataAddhandler",[
                {"scenario":undefined},
                {"troop":undefined}
            ]
            ,commonConstants.dataOperateType.DataHandler,"增加数据存储的连接地址"),
            new Configurantion("dataUpdatahandler",[
                {"scenario":undefined},
                {"troop":undefined}
            ],commonConstants.dataOperateType.DataHandler,"修改数据存储的连接地址"),
            new Configurantion("dataDelhandler",[
                {"scenario":undefined},
                {"troop":undefined}
            ],commonConstants.dataOperateType.DataHandler,"删除数据存储的连接地址")
        );

        //根据类型分类
        this.configurations.forEach(config =>{
            let curType = config.getType();
            if(!this.configurationTYpes.has(curType)){
                this.configurationTYpes.set(curType,[]);
            }
            this.configurationTYpes.get(curType).push(config);
        })
    }

    /**
     * 通过类型来获得配置
     * @param {String} type 
     */
    getConfigurationsByType(type){
        return this.configurationTYpes.get(type);
    }

      /**
     * 通过类型来获得配置
     * @param {String} key
     */
      getconfigurationByKey(key){
        return commonMethod.findElementFromArray(this.configurations,e=>e.getKey() == key);
    }

    /**
     * 配置修改
     * @param {Array} configs 
     */
    updataConfigurations(configs){
        if(undefined != configs){
            configs.forEach(c=>{
                this.updataConfiguration(c)
             })
        }   
    }

    /**
     * 修改配置
     * @param  c 
     */
    updataConfiguration(c){
        let  curConfigurantion = this.getconfigurationByKey(c.key);
        curConfigurantion.updateValue(c.value);
    }

    /**
     * 控制台输出配置
     */
    showConfigurations(){
        for (const configuration of this.configurations) {
            configuration.show();
        }
    }
   
}

class Configurantion{
    // key;defualtValue;type;description;value=undefined
    constructor(key,defualtValue,type,description,value){
        this.key = key;
        this.defualtValue = defualtValue;
        this.type = type;
        this.description = description;
        this.value = value
    }

    updateValue(v){
        this.value = v;
    }

    getType(){
        return this.type;
    }

    getKey(){
        return this.key;
    }

    getValue(){
        if(this.value == undefined){
            return this.defualtValue;
        }
        return this.value;
    }

    show(){
        console.log(this.key+":"+this.description+"默认值："+this.defualtValue);
    }
}


export default ScenarioConfiguration;